import React, { Component } from 'react';
import { connect } from 'dva'
import { Form, Table, Button, Select, Tag ,Input} from 'antd';
import SuperForm from '../../../components/SuperForm'
import ReactQuill from "react-quill"
import 'react-quill/dist/quill.snow.css'
const { Option } = Select

const mapStateToProps = (state) => {
    return {
        userInfo:state.user.info,
        ...state.questions
    }
}

@connect(mapStateToProps)
class addlist extends Component {

  state = {
    loading: true
  }

 
  handlerSubmit = (payload = {}) => {
    console.log(payload, '提交')
    this.props.dispatch({
        type: 'questions/createQuestions',
        payload: {
            ...payload,
            user_id: this.props.userInfo.user_id
        }

    }).then((res) => {
        console.log(res, '成功')
        // message.success(res.msg)
       
    })

}

  fetchQuestions = (payload = {}) => {
    console.log(payload)
    this.setState({
      loading: true
    }, () => {
      this.props.dispatch({
        type: 'questions/fetchQuestions',
        payload
      }).then(() => {
        this.setState({
          loading: false
        })
      })
    })
  }
  get form_config () {
    const {
        questionsType, // 试题类型
        subject, // 所有课程
        examType, // 考试类型
      } = this.props
     return [
        {
            label: '题目',
            name: 'title',
            content: 'Input',
            defaultValue:'11'
        },
        {
            label: '题干',
            name: 'questions_stem',
            content: <ReactQuill theme="snow"/>,
            defaultValue:'11'
        },
        {
            label: '试题类型',
            name: 'questions_type_id',
            content: 'Select',
            options: questionsType.map(item => ({
                value:item.questions_type_id,
                text:item.questions_type_text
            })),
            defaultValue:'11'
        },
        {
            label: '试题课程',
            name: 'subject_id',
            content: 'Select',
            options: subject.map(item => ({
                value:item.subject_id,
                text:item.subject_text
            })),
            defaultValue:'11'
        },
        {
            label: '考试类型',
            name: 'exam_id',
            content: 'Select',
            options: examType.map(item => ({
                value:item.exam_id,
                text:item.exam_name
            })),
            defaultValue:'11'
        },
        {
          label: '答案',
          name: 'questions_answer',
          content: <ReactQuill theme="snow"/>,
          defaultValue:'11'
      },
     ]
  }
  render() {

    // const layout = {
    //     labelCol: { span: 1 },
    //     wrapperCol: { span: 16 },
    //   };
    //   const tailLayout = {
    //     wrapperCol: { offset: 8, span: 16 },
    //   };
  
    return (
      <div>
        <div className="filter-bar">
            <SuperForm
            items={this.form_config}
            onSubmit={this.handlerSubmit}
            >

            </SuperForm>
        </div>
      </div>
    );
  }
}

export default addlist